package com.yami.shop.delivery.common.listener;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yami.shop.bean.event.ClearPolygonPathEvent;
import com.yami.shop.delivery.common.model.SameCity;
import com.yami.shop.delivery.common.service.SameCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

;
;

@Component("SameCityListener")
public class SameCityListener {

    @Autowired
    private SameCityService sameCityService;

    /**
     * 清除同城配送中坐标数据
     * @param event
     */
    @EventListener(ClearPolygonPathEvent.class)
    public void clearPolygonPath(ClearPolygonPathEvent event) {
        SameCity sameCity = new SameCity();
        sameCity.setShopId(event.getShopId());
        sameCity.setPositionIds("[]");
        sameCityService.update(sameCity, new LambdaUpdateWrapper<SameCity>()
                .eq(SameCity::getShopId, event.getShopId()));
        sameCityService.removeCache(event.getShopId());
    }
}
